package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-09-11
 * Time: 14:57
 */
public class demo11 {

    public static void main(String[] args) {
        Thread t=new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //e.printStackTrace();
                    break;
                }
            }
            System.out.println("线程执行完了");
        },"这是我的线程");
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        t.interrupt();//主线程通过这个中断线程，设置标志位为true
        System.out.println("设置让t 结束");
    }
}
